package com.lecture.java8.lambda;

import com.lecture.java8.lambda.entity.User;

import java.util.Arrays;
import java.util.List;

/**
 * @program: spring-lecture
 * @description:
 * @author: luyn
 * @create: 2020-03-26 19:23
 **/
public class TestLambda2 {



    public static void main(String[] args) {
        List<User> userList = Arrays.asList(
                new User(1, "H张三", 13),
                new User(2, "B李四", 72),
                new User(3, "A王五", 16),
                new User(4, "D赵六", 31),
                new User(5, "E薛七", 53)
        );


        /*Collections.sort(userList, (user1, user2) -> {
            if (user1.getAge() == user2.getAge()) {
                return user1.getName().compareTo(user2.getName());
            } else {
                return -Integer.compare(user1.getAge(), user2.getAge());
            }
        });

        userList.forEach(System.out::println);

        TestLambda2 testLambda2 = new TestLambda2();
        String value = testLambda2.strHandler("abadc", (str -> str.toUpperCase()));
        System.out.println(value);

        // 对于两个long型进行处理
        Long lValue = testLambda2.op(1L, 2L, (x, y) -> x + y);
        System.out.println(lValue);*/
        /*userList.stream()
                    .sorted(Comparator.comparing(User::getName))
                .forEach(user -> {
            System.out.println(user.getName());
        });*/

        /*String[] strings = userList.stream()
                .sorted(Comparator.comparing(User::getName).reversed())
                .map(User::getName)
                .toArray(String[]::new);
        for (String string : strings) {
            System.out.println(string);
        }*/
    }

    // 处理字符串 返回处理后的字符串
    public String strHandler(String str, MyFunction myFunction) {
        return myFunction.getValue(str);
    }

    //
    public Long op(Long l1, Long l2, MyFunction2<Long, Long> myFunction2) {
        return myFunction2.getValue(l1, l2);
    }
}
